import java.io.*;

public class b3965 {
    static int[] nums = new int[100001];
    public static void main(String[] args) throws IOException {
        PrintWriter p = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        StreamTokenizer sc = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        sc.nextToken();
        int n = (int) sc.nval;
        for(int i = 0; i < n; i++){
            sc.nextToken();
            nums[i] = (int) sc.nval;
        }
        for(int i = 0; i < n; i++){
            int ret = nums[i];
            if( i + 1 != nums[ret - 1]){
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}
